//
//  NoticeVC.swift
//  YueChat
//
//  Created by IMac on 2024/10/9.
//

import UIKit

class NoticeVC: BaseVC {

    var group = DMCCGroup()
    @IBOutlet weak var textView: UITextView!
    
    init(group: DMCCGroup) {
        super.init(nibName: nil, bundle: nil)
        self.group = group
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        textView.becomeFirstResponder()
        
        self.textView.text = self.group.billboard
    }

    @IBAction func onBack(_ sender: Any) {
        dismiss(animated: true)
    }
    
    @IBAction func done(_ sender: Any) {
        guard textView.text.count <= 1500 else {
                MHAlert.showMessage(KLocalizedString("StringLength"))
                return
            }
            
            MHAlert.showLoading()

//        DMCCIMService.getInstance().addBillBoard(group.groupId, data: textView.text) { isSuccess, json, err in
//            if isSuccess {
//                DispatchQueue.main.async {
//                    MHAlert.showMessage(KLocalizedString("GroupMessageBeenSended"))
//                    self.dismiss(animated: true)
//                }
//            } else {
//                DispatchQueue.main.async {
//                    MHAlert.showMessage(KLocalizedString("GroupMessageTimeOut"))
//                }
//            }
//        }
        Task{
            let res = await gosnGroup.setGroupBillboard(group.groupId, textView.text)
            await MainActor.run {
                if res{
                    MHAlert.showMessage(KLocalizedString("GroupMessageBeenSended"))
                    self.dismiss(animated: true)
                }else{
                    MHAlert.showMessage(KLocalizedString("GroupMessageTimeOut"))
                }
            }
        }
        

    }


}
